#include "list.h"

BOOL ListCreate( LIST_t * list )
{
    list->first_node == NULL;
    list->nr_elements = 0;

    return TRUE;
}

BOOL ListAdd( LIST_t * list, void * data )
{
    NODE_t * new_node;

    new_node = calloc( 1, sizeof( * new_node ) );

    if ( new_node != NULL )
    {
        list->nr_elements++;
        new_node->data = data;

        if ( list->first_node == NULL )
        {
            list->first_node = new_node;
            new_node->next = NULL;
        }
        else
        {
            new_node->next = list->first_node;
            list->first_node = new_node;
        }

        return TRUE;  
    }

    return FALSE;
}

unsigned int ListGetNrElements( LIST_t * list )
{
    return list->nr_elements;
}

void ListDestroy( LIST_t * list )
{
}

void * ListGet( LIST_t * list, int nr )
{
    NODE_t * new_node;
    int i;

    new_node = list->first_node;

    for ( i = 0; i < nr; i++ )
    {
        if ( new_node == NULL )
            break;

        new_node = new_node->next;
    }

    if ( new_node == NULL ) 
        return NULL;

    return new_node->data;
}
